import service from './index'

// 考试相关API
export const examApi = {
  // 获取考试列表
  getExamList(params) {
    // 暂时返回模拟数据
    return Promise.resolve({
      data: [
        {
          id: 1,
          title: '前端开发基础考试',
          questionCount: 50,
          duration: 90,
          totalScore: 100,
          createTime: '2023-01-01'
        },
        {
          id: 2,
          title: '后端开发进阶考试',
          questionCount: 60,
          duration: 120,
          totalScore: 120,
          createTime: '2023-01-02'
        }
      ]
    })
  },

  // 获取考试详情
  getExamDetail(id) {
    // 暂时返回模拟数据
    return Promise.resolve({
      data: {
        id: id,
        title: '前端开发基础考试',
        questionCount: 50,
        duration: 90,
        totalScore: 100,
        questions: [
          {
            id: 1,
            type: 'single',
            title: 'HTML的全称是什么？',
            score: 2,
            options: [
              { id: 'A', label: 'A', content: 'Hyper Text Markup Language' },
              { id: 'B', label: 'High Tech Modern Language' },
              { id: 'C', label: 'Home Tool Markup Language' },
              { id: 'D', label: 'Hyperlink and Text Markup Language' }
            ]
          },
          {
            id: 2,
            type: 'multiple',
            title: '以下哪些是CSS的选择器？',
            score: 3,
            options: [
              { id: 'A', label: 'A', content: '.class' },
              { id: 'B', label: 'B', content: '#id' },
              { id: 'C', label: 'C', content: 'tag' },
              { id: 'D', label: 'D', content: '* (通配符)' }
            ]
          }
        ]
      }
    })
  },

  // 开始考试
  startExam(examId) {
    // 暂时返回模拟数据
    return Promise.resolve({
      data: {
        examId: examId,
        startTime: new Date().toISOString(),
        endTime: new Date(Date.now() + 90 * 60 * 1000).toISOString()
      }
    })
  },

  // 提交答案
  submitAnswer(data) {
    // 暂时返回模拟数据
    return Promise.resolve({
      data: {
        score: 85,
        correctCount: 42,
        totalCount: 50,
        passed: true
      }
    })
  },

  // 获取考试结果
  getExamResult(examId) {
    // 暂时返回模拟数据
    return Promise.resolve({
      data: {
        examId: examId,
        score: 85,
        correctCount: 42,
        totalCount: 50,
        passed: true,
        ranking: 15,
        totalParticipants: 120
      }
    })
  },

  // 获取考试历史
  getExamHistory() {
    // 暂时返回模拟数据
    return Promise.resolve({
      data: [
        {
          examId: 1,
          examTitle: '前端开发基础考试',
          score: 85,
          date: '2023-01-15',
          passed: true
        },
        {
          examId: 2,
          examTitle: '后端开发进阶考试',
          score: 78,
          date: '2023-01-20',
          passed: true
        }
      ]
    })
  }
}

// 学习统计API
export const statisticsApi = {
  // 获取学习统计
  getLearningStatistics() {
    // 暂时返回模拟数据
    return Promise.resolve({
      data: {
        totalCourses: 12,
        completedCourses: 8,
        totalHours: 45,
        currentStreak: 7,
        longestStreak: 15
      }
    })
  },

  // 获取成就徽章
  getAchievements() {
    // 暂时返回模拟数据
    return Promise.resolve({
      data: [
        { id: 1, name: '学习新手', description: '完成第一门课程', icon: 'beginner' },
        { id: 2, name: '坚持不懈', description: '连续学习7天', icon: 'streak' },
        { id: 3, name: '课程专家', description: '完成10门课程', icon: 'expert' }
      ]
    })
  },

  // 获取学习日历
  getLearningCalendar() {
    // 暂时返回模拟数据
    return Promise.resolve({
      data: {
        year: 2023,
        month: 1,
        days: [
          { day: 1, hours: 2 },
          { day: 3, hours: 1.5 },
          { day: 5, hours: 3 },
          { day: 7, hours: 2.5 },
          { day: 10, hours: 1 },
          { day: 12, hours: 2 },
          { day: 15, hours: 3.5 }
        ]
      }
    })
  }
}